#include <stdio.h>
#include <time.h>
#include <stdint.h>
#include <stdint.h>

#include "../mickey_bitslice.h"

#define print_key(key,keyno)                 \
{                                            \
   int i;                                    \
   printf ("Key       [%2d]   =",keyno);     \
   for (i=0; i<10; i++)                      \
      printf (" %02x", key[i]);              \
   printf ("\n");                            \
}                                            \

#define print_iv(iv,ivlen,ivno)              \
{                                            \
   int i;                                    \
   printf ("IV        [%2d]   =",ivno);      \
   for (i=0; i<(iv_len+7)/8; i++)            \
      printf (" %02x", iv[i]);               \
   printf ("\n");                            \
}                                            \


void example_1(void) {

   int i,stream;

   uint8_t key_1[10] = {0xf1,0x1a,0x56,0x27,0xce,0x43,0xb6,0x1f,0x89,0x12};
   uint8_t iv_1[10]  = {0x9c,0x53,0x2f,0x8a,0xc3,0xea,0x4b,0x2e,0xa0,0xf5};

   uint8_t keystream_buff[16][MICKEY_NR_STREAMS], *keystream_byte;

   int iv_len = 80;
   int nr_streams = 1; /* for the example only using a subset */

   mickey_state ctx;

   /* create context */
   mickey_init(&ctx);

   /* load keys and IVs*/
   
#define  __load_print_key_iv(key,iv,iv_len,no)                  \
   mickey_load_key(&ctx,key); mickey_load_IV(&ctx,iv,iv_len);   \
   print_key(key,no);          print_iv(iv,iv_len,no);          \
   printf("\n");                                                \
   
   __load_print_key_iv(key_1,iv_1,iv_len, 0);

#undef  __load_print_key_iv


   /* do the actual key loading and initialization */
   mickey_setup(&ctx);

   /* generate keystream */
   for(i=0;i<16;i++) {
      keystream_byte=keystream_buff[i];
      mickey_keystream_byte(&ctx,keystream_byte);
   }

   for(stream=0;stream<nr_streams;stream++) {
      printf ("Keystream [%2d]   =",stream);
      for(i=0;i<16;i++) {
         printf(" %02x",keystream_buff[i][stream]);
      }
      printf("\n");
   }
}

int main(void) {
   example_1();
   return 0;
}
